## This software is licensed by the MIT License, see LICENSE file ##
##                                    Copyright © 2022 whitemangl ##

from typing import Union

from aiogram.types import InputMediaAudio
from aiogram.types import InputMediaDocument
from aiogram.types import InputMediaPhoto
from aiogram.types import InputMediaVideo
from aiogram.types import InputFile

from aiogram.types import Message

from .Configuration import Configuration
from .TGPBot        import TGPBot


def switch_media(message: Message) -> Union[InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo]:
    class TGPBotUnexpectedMedia(Exception):
        pass

    if message.document:
        return InputMediaDocument(type="document", media=message.document.file_id)
    if message.video:
        return InputMediaVideo(type="video", media=message.video.file_id)
    if message.audio:
        return InputMediaAudio(type="audio", media=message.audio.file_id)
    if message.photo:
        m = 0
        f = 0
        
        for v in message.photo:
            if (v.file_size > m):
                m = v.file_size
                f = v.file_id
        return InputMediaPhoto(type="photo", media=f)

    raise TGPBotUnexpectedMedia("Unexpected media type")
